ZF.add('browser', function(Z) {

    var win = window,
        doc = document,
        ua = navigator.userAgent.toLowerCase(),
        UA = ua.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0],
	    platform = navigator.platform.toLowerCase(),
        mode = UA[1] == 'ie' && doc.documentMode;

    var Browser = {

        name : (UA[1] == 'version') ? UA[3] : UA[1],
        
        version : mode || parseFloat((UA[1] == 'opera' && UA[4]) ? UA[4] : UA[2]),
        
        Platform : {
            name : ua.match(/ip(?:ad|od|hone)/) ? 'ios' : (ua.match(/(?:webos|android)/) || platform.match(/mac|win|linux/) || ['other'])[0]
        },
        
        Features : {
            xpath : !!(doc.evaluate),
            air : !!(win.runtime),
            query : !!(doc.querySelector),
            json : !!(win.JSON)
        },
        
        Plugins : {
            range : doc.implementation.hasFeature("Range", "2.0")
        }

    };

    Browser[Browser.name] = true;
    Browser[Browser.name + parseInt(Browser.version, 10)] = true;
    Browser.Platform[Browser.Platform.name] = true;

    // HttpRequest
	Browser.Request = function() {
		try {
			return new XMLHttpRequest();
		} catch(e) {
			try {
				return new ActiveXObject('MSXML2.XMLHTTP');
			} catch(e) {
				try {
					return new ActiveXObject('Microsoft.XMLHTTP');
				} catch(e) {
					
				}
			}
		}
		return;
	}

    // xhr feature check
	Browser.Features.xhr = !!(Browser.Request());

    // 
    if (doc.execCommand) {
        try {
	        doc.execCommand("BackgroundImageCache", false, true);
        } catch (e){}
    }

    // Flash detection
    var version, v;
    try {
        v = navigator.plugins['Shockwave Flash'].description;
    } catch(e) {
        try {
            v = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
        } catch(e) {
        }
    }
    version = (v || '0 r0').match(/\d+/g);

    Browser.Plugins.Flash = {
        version : Number(version[0] || '0.' + version[1]) || 0,
        build : Number(version[2]) || 0
    };

    
    Browser.exec = function(text) {
        if (!text) {
            return text;
        }

        if (win.execScript){
            win.execScript(text);
        } else {
            var script = doc.createElement('script');
            script.setAttribute('type', 'text/javascript');
            script.text = text;
            doc.head.appendChild(script);
            doc.head.removeChild(script);
        }

        return text;
    };


    /*
    // element style's position fixed
	Browser.POSITION_FIXED = Browser.ie && Browser.ie6;
	
	Browser.maxthon = (function(){
        try {
			var tc = win.external.tab_count;
			return typeof(tc) != "undefined";
		} catch(e) {}

		return false;
	})();
	
	Browser.tt = (function(){
		if (Browser.maxthon || ua.indexOf("tencent") == -1) {
            return false;
        }
        
        try {
			win.external.ShowBrowserUI('7k7k');
			return true;
		} catch(e){}
		
        return false
	})();
	
	if(Browser.tt) {
		try {
			var v = win.external.getTTVerStr();
			if(v.indexOf('Tencent') >= 0) {
				Browser.TTVer = v;
				var ttVer = Browser.TTVer.replace('Tencent Traveler ', '').split(' ')[0].split('.');
				Browser.TTVerMaj = parseInt(ttVer[0] + ttVer[1]) || 0;
			}
		} catch(e) {}
	}
	Browser.getTTVer = function(){ return Browser.TTVer ? Browser.TTVer.replace('Tencent Traveler ', '') : ''; };
	
	if(Browser.maxthon){
		try {
			Browser.MAXVer = win.external.max_version;
			var maxVer = Browser.MAXVer.split('.');
			Browser.MAXVerMaj = parseInt(maxVer[0] + maxVer[1] + maxVer[2]) || 0;
		} catch(e) {}
	}
	Browser.getMaxVer = function() { return Browser.MAXVer || ''; };

	Browser.matterExplorer = Browser.maxthon || Browser.tt;

	// wmode bug check(遨游/TT 独立视频播放功能 造成FLASH的Wmode参数强制变为window的BUG)
	if (Browser.matterExplorer && (Browser.MAXVerMaj > 254 || Browser.TTVerMaj > 44)) {
        Browser.swfWmodeTrouble = true;
    }
    */


    Z.Browser = Browser;

});